package team12.Session;

import java.sql.Timestamp;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import team12.Entity.*;

public class UserSessionBean {

	@PersistenceContext(unitName = "ProjectManagementSystem-EJB")
	EntityManager em;
	
	/*
	 * For all users
	 * */
	
	public long validateUser(String userName, String password){
		Table_Member user = new Table_Member();
		return user.getMemberId();
	}
	
	public int getAuthority(long userId){
		Table_Member user = new Table_Member();
		return user.getAuthority();
	}
	
	public long createUser(String memName, String memGender, String memBirthday, String memEmail, String memPassword, 
			String regTime, String lloginTime){
		Table_Member user =  new Table_Member();
		//Initiating: use Table_Member(String memName, String memGender, String memBirthday, String memEmail, String memPassword, 
		//String regTime, String lloginTime, int memAuthority)
		//default value of athority = 3
		//register and lastLoginTime = java.util.Date date= new java.util.Date();
		em.persist(user);
		return user.getMemberId();
	}
	
	
	/*
	 * For project managers
	 * */
	
	public List<Table_Project> getProjects(){
		List<Table_Project> projects;
		//Query statments for getting project list
		return projects;
	}
	
	public Table_Project getProByProId(long proId){
		Table_Project project;
		//Query statments for getting project
		return project;
	}
	
	public List<Table_Team> getTeamsByProId(long proId){
		List<Table_Team> teams;

		//Query statments for getting a team list
		return teams;
	}
	
	public List<Table_Member> getEngrsByTeamId(long teamId){
		List<Table_Member> engineers;
		//Query statments for getting an engineer list
		return engineers;
	}
	
	public long createTeam(String teamName, long teamLeaderId){
		Table_Team team;
		//Creating: teamName, CreTime, teamLeaderId
		em.persist(team);
		return team.getTeamId();
	}
	
	public void removeTeam(long teamId){
		//Statement to remove teams
	}
	
	
	/*
	 *  For Team Leaders
	 * */
	
	public Table_Team getTeamsByLeaderId(long teamLeaderId){
		Table_Team team;
		//Query statments for getting a team list
		return team;
	}
	
	//getEngrsByTeamId method can be found above
	
	public Table_Member getEngrById(long EngrId){
		Table_Member engineer;
		//Query Statement for getting an engineer 
		return engineer;
	}
	
	public Table_Team getTeamByTeamId(long teamId){
		Table_Team team;
		//Query Statement for getting the team
		return team;
	}
	
	public void evaluateEngr(Table_Member engr, String eva){
		Table_Evaluation evaluation = new Table_Evaluation(engr, eva); 
		em.persist(evaluation);	
	}
	
	
	/*
	 * For engineers
	 * */
	
	public long createFile(Table_Member mem, String fileName, Table_Team t){
		Table_Member member = mem;
		Table_Team team = t;
		Table_File file;
		
		//file path shoud be associated with teamId
		
		//creator and lastEditor are the same in this case
		//createTime and lastEditTime are the same in this case
		return file.getFileId();
	}
	
	public Table_File getFileByFileId(long fId){
		Table_File file;
		//Query Statement for getting a file
		return file;
	}
	
	public void deleteFile(long fileId){
		//Statement to remove the file
	}
	
	public List<Table_FileComment> getCommentsByFileId(long fId){
		List<Table_FileComment> fileComments;
		//Query Statement for getting a comment list
		return fileComments;
	}
	
	public long createFileComment(long fileId, String cont, Table_Member reviewer){
		Table_FileComment comment;
		em.persist(comment);
		
		return comment.getCommentId();
	}
	
	public void deleteFileComment(long fileId, long userId){
		//Statement to remove a comment form a file 
	}
	
	/*
	 * Announcement
	 * */
	
	public Table_Announcement getAnnByTeamId(long tId){
		Table_Announcement announcement;
		//Query Statement to get announcement
		
		return announcement;
	}
	
	public long createAnnouncement(long tId, String tt, String conts){
		Table_Announcement announcement;
		//postTime and lastEdittime shoud be the same
		em.persist(announcement);		
		return announcement.getAnnouncementId();
	}
	
	public void deleteAnnouncement(long annId, long tId){
		//Statement to remove an announcement
	}
	
	public Table_AnnouncementComment getAnnCommByAnnId(long annId){
		Table_AnnouncementComment announcementComment;
		//Query Statement to get announcement comments
		return announcementComment;
	}
	
	public long createAnnouncementComment(long annId, String conts, long memId){
		Table_AnnouncementComment announcementComment;
		//postTime should be current system time
		em.persist(announcementComment);
		return announcementComment.getCommentId();
	}
	
	public void deleteAnnouncementComment(long annId, long reviewerId){
		//Statement to remove an announcement comment
	}
}
